package com.PAT.UnSatisfying;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/12/27/17:57
 * @Description:
 * @Target:差6
 */
public class MOOC期终成绩 {
    public static void main(String[] args) {
        // 变量设定：P M N
        // 对于三大组数据，只能使用容器，但是需要判断name，然后存入对应的属性。
        Scanner in = new Scanner(System.in);
        HashMap<String,StudentGrade> map = new HashMap<>();


        String s1 = in.nextLine();
        String[] s = s1.split(" ");

        int P = Integer.valueOf(s[0]);
        int M = Integer.valueOf(s[1]);
        int N = Integer.valueOf(s[2]);

        while (P-->0){
            String ss = in.nextLine();
            String[] s2 = ss.split(" ");
            String name = s2[0];
            int GP = Integer.valueOf(s2[1]);
            if (!map.containsKey(name)){
                map.put(name,new StudentGrade(name,GP,0,0));
            }else {
                map.put(name,map.get(name).setGP(GP));
            }
        }


        while (M-->0){
            String ss = in.nextLine();
            String[] s2 = ss.split(" ");
            String name = s2[0];
            int GM = Integer.valueOf(s2[1]);
            if (!map.containsKey(name)){
                map.put(name,new StudentGrade(name,0,GM,0));
            }else {
                map.put(name,map.get(name).setGM(GM));
            }
        }



        while (N-->0){
            String ss = in.nextLine();
            String[] s2 = ss.split(" ");
            String name = s2[0];
            int GF = Integer.valueOf(s2[1]);
            if (!map.containsKey(name)){
                map.put(name,new StudentGrade(name,0,0,GF));
            }else {
                map.put(name,map.get(name).setGF(GF));
            }
        }


        Map<String,StudentGrade> map1 = new TreeMap(new StudentGradeCompare(map));


        for (Map.Entry<String, StudentGrade> entry : map.entrySet()) {
            String mapKey = entry.getKey();
            StudentGrade mapValue = entry.getValue();
            map1.put(entry.getKey(),entry.getValue());
        }



        for (Map.Entry<String, StudentGrade> entry : map1.entrySet()) {
            String mapKey = entry.getKey();
            StudentGrade mapValue = entry.getValue();
            if (mapValue.getGM()==0){
                mapValue.setGM(-1);
            }
            if (mapValue.getGF()==0){
                mapValue.setGF(-1);
            }

            if (mapValue.getGS()>=60){
                System.out.println(mapValue.name+" "+mapValue.getGP()+" "+mapValue.getGM()+" "+mapValue.getGF()+" "+mapValue.getGS());
            }
        }


    }


    static class StudentGradeCompare implements Comparator<String>{

        Map<String, StudentGrade> base;
        //这里需要将要比较的map集合传进来
        public StudentGradeCompare(Map<String, StudentGrade> base) {
            this.base = base;
        }
        public int compare(String o1, String o2) {
            if (base.get(o1).getGS() == base.get(o2).getGS()){
                return (o1).compareTo(o2);
            }else {
                return -(int)(base.get(o1).getGS()-base.get(o2).getGS());
            }
        }
    }

    // 成绩：GS总  GP平时  GM期中  GF期末
    // 考虑创建对象，那么每次进值就得遍历，但是对于后来不断进值，有三个数组，那么对象是比较好的方法了。
    static class StudentGrade{
        private String name;
        private int GP;
        private int GM;
        private int GF;
        private double GS;

        public StudentGrade() {
        }


        public StudentGrade(String name, int GP, int GM, int GF) {
            this.name = name;
            this.GP = GP;
            this.GM = GM;
            this.GF = GF;
        }

        public int getGS() {
            if (this.GP>=200){
                if (this.GM>this.GF){
                    this.GS = this.GM * 0.4 + this.GF * 0.6;
                }else {
                    this.GS = this.GF;
                }

            }else {
                this.GS = 0;
            }

            if (this.GS<60){
                this.GS= 0;
            }
            return (int) Math.round(GS);
        }

        public int getGP() {
            return GP;
        }

        public StudentGrade setGP(int GP) {
            this.GP = GP;
            return this;
        }

        public int getGM() {
            return GM;
        }

        public StudentGrade setGM(int GM) {
            this.GM = GM;
            return this;
        }

        public int getGF() {
            return GF;
        }

        public StudentGrade setGF(int GF) {
            this.GF = GF;
            return this;
        }


        @Override
        public String toString() {
            return "StudentGrade{" +
                    "name='" + name + '\'' +
                    ", GP=" + GP +
                    ", GM=" + GM +
                    ", GF=" + GF +
                    ", GS=" + getGS() +
                    '}';
        }
    }
}


